package com.tanhua.server.controller;

import com.tanhua.domain.mongo.Publish;
import com.tanhua.server.service.MovementsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author liuyp
 * @date 2021/01/30
 */
@RestController
@RequestMapping("/movements")
public class MovementsController {

    @Autowired
    private MovementsService movementsService;

    /**
     * 圈子-推荐动态
     * GET /movements/recommend
     */
    @GetMapping("/recommend")
    public ResponseEntity findRecommendPublishList(int page, int pagesize){
        return movementsService.findRecommendPublishList(page, pagesize);
    }

    /**
     * 圈子-发布动态
     * POST /movements
     */
    @PostMapping
    public ResponseEntity savePublish(Publish publish, String location, MultipartFile[] imageContent) throws IOException {
        publish.setLocationName(location);
        return movementsService.savePublish(publish, imageContent);
    }

    /**
     * 圈子-好友动态
     * GET /movements
     */
    @GetMapping
    public ResponseEntity findFriendPublishList(int page, int pagesize){
        return movementsService.findFriendPublishList(page, pagesize);
    }

    /**
     * 我的-我的动态
     * GET /movements/all
     */
    @GetMapping("/all")
    public ResponseEntity findAlbumPublishList(@RequestParam(defaultValue = "1") int page,
                                               @RequestParam(defaultValue = "10") int pagesize,
                                               @RequestParam(required = false) Long userId){
        return movementsService.findAlbumPublishList(page, pagesize, userId);
    }

    /**
     * 圈子-评论-点赞
     * GET /movements/:id/like
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String publishId){
        return movementsService.like(publishId);
    }

    /**
     * 圈子-评论-取消点赞
     * GET /movements/:id/dislike
     */
    @RequestMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String publishId){
        return movementsService.dislike(publishId);
    }

    /**
     * 圈子-评论-显示单条动态
     * GET /movements/:id
     */
    @GetMapping("/{id}")
    public ResponseEntity findPublishById(@PathVariable("id") String publishId){
        return movementsService.findPublishById(publishId);
    }

    /**
     * 谁看过我
     * GET/movements/visitors
     */
    @GetMapping("/visitors")
    public ResponseEntity findVisitorsList(){
        return movementsService.findVisitorList();
    }
}
